<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>3152：[Ctsc2013]组合子逻辑</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Ctsc2013]组合子逻辑</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Ctsc2013]组合子逻辑</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Ctsc2013]组合子逻辑                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>
<div style="margin: 6pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">组合子逻辑是</span><span style="color: black">Moses </span><span style="color: black">&nbsp;</span><span style="color: black">Sch&ouml;nfinkel</span><span style="color: black">和</span><span style="color: black">Haskell </span><span style="color: black">&nbsp;</span><span style="color: black">Curry</span><span style="color: black">发明的一种符号系统，用于消除数理</span></span><span style="font-size: medium"><span style="color: black">逻辑中对于变量的需要。本题考察一种与真实世界的组合子演算略有差别的组合子系统。 </span></span><span style="font-size: medium"><span style="color: black">一个组合子项是下列形式之一： </span></span></div>
<div style="margin: 6pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">P</span><span style="color: black">&nbsp;</span></span></div>
<div style="margin: 5pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">(</span><span style="color: black">E</span><span style="color: black">1</span> <span style="color: black">E</span><span style="color: black">2</span><span style="color: black">) </span></span></div>
<div style="margin: 2pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">其中</span><span style="color: black">P表示一个基本函数，E</span><span style="color: black">1</span><span style="color: black">以及</span><span style="color: black">E</span><span style="color: black">2</span><span style="color: black">表示一个组合子项</span><span style="color: black">(</span><span style="color: black">可以相同</span><span style="color: black">)。不满足以上形式的</span></span><span style="font-size: medium"><span style="color: black">表达式均非组合子项。 </span></span></div>
<div style="margin: 5pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">我们将一个组合子项</span><span style="color: black">E</span><span style="color: black">的参数个数</span><span style="color: black">np(E)</span><span style="color: black">如下： </span></span></div>
<div style="margin: 6pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">np(P) = </span><span style="color: black">&nbsp;</span><span style="color: black">基本函数</span><span style="color: black">P</span><span style="color: black">的参数个数； </span></span></div>
<div style="margin: 5pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">np((</span><span style="color: black">E</span><span style="color: black">1</span> <span style="color: black">E</span><span style="color: black">2</span><span style="color: black">)) = np(</span><span style="color: black">E</span><span style="color: black">1</span><span style="color: black">) - 1</span><span style="color: black">。 </span></span></div>
<div style="margin: 2pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">本题中，我们用一个正整数同时表示一个基本函数，以及该基本函数的参数个数。 </span></span><span style="font-size: medium"><span style="color: black">对于一个组合子项</span><span style="color: black">E</span><span style="color: black">，如果它和它包含的所有组合子项的参数个数</span><span style="color: black">np</span><span style="color: black">均为正整数，那</span></span><span style="font-size: medium"><span style="color: black">么我们称这个</span><span style="color: black">E</span><span style="color: black">为范式。 </span></span></div>
<div style="margin: 6pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">我们经常组合子项简化表示：如果一个组合子项</span><span style="color: black">E含有连续子序列(</span><span style="color: black">&hellip; </span><span style="color: black">&nbsp;</span><span style="color: black">((</span><span style="color: black">E</span><span style="color: black">1</span> &nbsp;<span style="color: black">E</span><span style="color: black">2</span><span style="color: black">) </span><span style="color: black">&nbsp;</span><span style="color: black">E</span><span style="color: black">3</span><span style="color: black">) </span><span style="color: black">&nbsp;&hellip; </span></span><span style="font-size: medium"><span style="color: black">En) (</span><span style="color: black">其中</span><span style="color: black">n </span><span style="color: black">&nbsp;</span><span style="color: black">&ge; </span><span style="color: black">&nbsp;</span><span style="color: black">3)</span><span style="color: black">，其中</span><span style="color: black">E</span><span style="color: black">k</span><span style="color: black">表示组合子项</span><span style="color: black">(</span><span style="color: black">可以是简化表示的</span><span style="color: black">)</span><span style="color: black">，那么将该部分替换为</span><span style="color: black">(</span><span style="color: black">E</span><span style="color: black">1</span> &nbsp;<span style="color: black">E2 </span></span><span style="font-size: medium"><span style="color: black">E</span><span style="color: black">3</span> &nbsp;<span style="color: black">&hellip; </span><span style="color: black">&nbsp;</span><span style="color: black">E</span><span style="color: black">n</span><span style="color: black">)</span><span style="color: black">，其他部分不变，得到表达式</span><span style="color: black">E</span><span style="color: black">的一个简化表示。一个组合子项可以被简化表示</span></span><span style="font-size: medium"><span style="color: black">多次。 </span></span><span style="font-size: medium"><span style="color: black">给定一个基本函数序列，问至少需要添加多少对括号，才能使得该表达式成为一个范式</span></span><span style="font-size: medium"><span style="color: black">的简化表示</span><span style="color: black">(</span><span style="color: black">即满足范式的性质</span><span style="color: black">)</span><span style="color: black">；如果无论如何怎样添加括号，均不能得到范式的简化表示，</span></span><span style="font-size: medium"><span style="color: black">输出</span><span style="color: black">-1</span><span style="color: black">。 </span></span></div>
</div></p><hr/><h3>输入格式</h3><p><p><span style="font-size: medium"><span style="color: black">&nbsp;&nbsp;&nbsp; 第一行包含一个正整数</span><span style="color: black">T</span><span style="color: black">，表示有</span><span style="color: black">T</span><span style="color: black">次询问。 </span></span><span style="font-size: medium"><span style="color: black">接下来</span><span style="color: black">2T</span><span style="color: black">行。 </span></span><span style="font-size: medium"><span style="color: black">第</span><span style="color: black">2k</span><span style="color: black">行有一个正整数</span><span style="color: black">n</span><span style="color: black">k</span><span style="color: black">，表示第</span><span style="color: black">k</span><span style="color: black">次询问的序列中基本函数的个数。 </span></span><span style="font-size: medium"><span style="color: black">第</span><span style="color: black">2k + 1</span><span style="color: black">行有</span><span style="color: black">n</span><span style="color: black">k</span><span style="color: black">个正整数，其中第</span><span style="color: black">i</span><span style="color: black">个整数表示序列中第</span><span style="color: black">i</span><span style="color: black">个基本函数。 </span></span></p>
<p></p></p><hr/><h3>输出格式</h3><p><div style="margin: 17pt 0cm 0pt">&nbsp;</div>
<div style="margin: 6pt 0cm 0pt 20pt"><span style="font-size: medium"><span style="color: black">输出</span><span style="color: black">T</span><span style="color: black">行，每行一个整数，表示对应询问的输出结果。 </span></span></div>
<p></p></p><hr/><h3>样例输入</h3><pre>2 
5 
3 2 1 3 2 
5 
1 1 1 1 1 

 

 
</pre><hr/><h3>样例输出</h3><pre>3 
-1 

 

 </pre><hr/><h3>提示</h3><p><p><br />
【样例说明】 <br />
第一次询问：一个最优方案是(3 (2 1) (3 2))。可以证明不存在添加括号对数更少的方案。 <br />
第二次询问：容易证明不存在合法方案。</p>
<p></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt; mso-pagination: none; mso-char-indent-count: 2.0"><font size="3"><span style="font-family: 宋体">令</span><span lang="EN-US" style="mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'"><font face="宋体">TN</font></span><span style="font-family: 宋体">表示输入中所有</span><span lang="EN-US" style="font-size: 12pt; font-family: &quot;Cambria Math&quot;; mso-bidi-font-family: 'Cambria Math'; mso-fareast-font-family: 'Times New Roman'">n</span></font><span lang="EN-US" style="font-size: 8.5pt; font-family: &quot;Cambria Math&quot;; mso-bidi-font-family: 'Cambria Math'; mso-fareast-font-family: 'Times New Roman'">k</span><span style="font-family: 宋体"><font size="3">的和。<span lang="EN-US" style="color: black">TN</span><span style="color: black">&le;<span lang="EN-US">2000000</span></span></font><span lang="EN-US"><o:p></o:p></span></span></p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=3152" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=3152" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>